/// @tags: ACAutoMaton
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>

using namespace std;

namespace BlueQuantum {

int const N = 755, M = 1e7 + 5;

int n, tot = 1;
int len[N], end[N], tr[M][2], fail[M], fa[M], tar[M], d[N][N], vis[N], match[N];
char s[M];
queue<int> q;

bool dfs(int x) {
  for (int i = 1; i <= n; ++i)
    if (d[x][i] && !vis[i]) {
      vis[i] = 1;
      if (!match[i] || dfs(match[i])) return match[i] = x, true;
    }
  return 0;
}

inline void insert(int i) {
  int cur = 1, len = strlen(s + 1);
  for (int j = 1; j <= len; ++j) {
    int c = s[j] - 'a';
    if (!tr[cur][c]) tr[cur][c] = ++tot, fa[tot] = cur;
    cur = tr[cur][c];
  }
  end[i] = cur, tar[cur] = i;
}

inline void build() {
  for (int i = 0; i < 2; ++i)
    if (tr[1][i]) fail[tr[1][i]] = 1, q.push(tr[1][i]);
    else
      tr[1][i] = 1;
  while (q.size()) {
    int x = q.front();
    q.pop();
    for (int i = 0; i < 2; ++i)
      if (tr[x][i]) fail[tr[x][i]] = tr[fail[x]][i], q.push(tr[x][i]);
      else
        tr[x][i] = tr[fail[x]][i];
  }
}

inline int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> (s + 1);
    insert(i);
  }
  build();
  tar[1] = -1;
  vector<int> tmp;
  for (int i = 1; i <= n; ++i)
    for (int j = end[i]; j != 1; j = fa[j]) {
      int x = fail[j];
      while (!tar[x]) tmp.push_back(x), x = fail[x];
      while (tmp.size()) fail[tmp.back()] = x, tmp.pop_back();
      fail[j] = x;
      if (j != end[i] && tar[j]) x = j;
      if (x != 1) d[i][tar[x]] = 1;
    }
  for (int k = 1; k <= n; ++k)
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j) d[i][j] |= d[i][k] & d[k][j];
  for (int i = 1; i <= n; ++i) d[i][i] = 0;
  int ans = n;
  for (int i = 1; i <= n; ++i) ans -= dfs(i), memset(vis, 0, sizeof(vis));
  cout << ans << '\n';
  for (int i = 1; i <= n; ++i) vis[match[i]] = 1;
  vector<int> s;
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) s.push_back(i);
  memset(vis, 0, sizeof(vis));
  bool flag = true;
  while (flag) {
    flag = false;
    for (vector<int>::iterator i = s.begin(); i != s.end(); ++i)
      for (int y = 1; y <= n; y++)
        if (d[*i][y]) vis[y] = 1;
    for (vector<int>::iterator i = s.begin(); i != s.end(); ++i)
      if (vis[*i]) {
        flag = true;
        while (vis[*i]) *i = match[*i];
      }
  }
  for (vector<int>::iterator i = s.begin(); i != s.end(); ++i) cout << *i << ' ';
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("CF590E Birthday.in", "r", stdin);
  freopen("CF590E Birthday.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
